package c0907m.group2.aitsm.gui.component;

import javax.swing.*;
import javax.swing.border.TitledBorder;
import java.awt.*;

/**
 * Created by IntelliJ IDEA.
 * User: ISTC
 * Date: 4/25/11
 * Time: 11:24 PM
 * To change this template use File | Settings | File Templates.
 */
public abstract class DefaultPanel extends JPanel implements Scrollable {

    public DefaultPanel() {
        super();
        initAll();
    }

    public DefaultPanel(String title) {
        setBorder(new TitledBorder(title));
    }

    private void initAll() {
        setBackground(new Color(255, 255, 255));
        setPreferredSize(new Dimension(850, 450));
    }

    //Override method from Scrollable interface
    @Override
    public Dimension getPreferredSize() {
        return getPreferredScrollableViewportSize();
    }

    //Override method from Scrollable interface
    @Override
    public Dimension getPreferredScrollableViewportSize() {
        return getSize();
    }

    //Override method from Scrollable interface
    @Override
    public int getScrollableUnitIncrement(Rectangle visibleRect, int orientation, int direction) {
        return 50;
    }

    //Override method from Scrollable interface
    @Override
    public int getScrollableBlockIncrement(Rectangle visibleRect, int orientation, int direction) {
        return 10;
    }

    //Override method from Scrollable interface
    @Override
    public boolean getScrollableTracksViewportWidth() {
        return getParent() != null ? getParent().getSize().width > getPreferredSize().width : true;
    }

    //Override method from Scrollable interface
    @Override
    public boolean getScrollableTracksViewportHeight() {
        return getParent() != null ? getParent().getSize().height > getPreferredSize().height : true;
    }

    /**
     * Reload data from database
     */
    public abstract void refresh();

    /**
     * Update data changes
     */
    public abstract void doUpdate();

    /**
     * Clear form input
     */
    public void doReset() {
        //to override
    }

    /**
     * Add data
     */
    public void doAdd() {
        //to override
    }

    /**
     * Print data
     */
    public void doPrint() {
        //to override
    }

}
